home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch3 / LogIndex.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-04-01  |  3.8 KB  |  126 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form frmLogIndex 
  4.    AutoRedraw      =   -1  'True
  5.    Caption         =   "LogIndex"
  6.    ClientHeight    =   5085
  7.    ClientLeft      =   1395
  8.    ClientTop       =   1005
  9.    ClientWidth     =   6915
  10.    LinkTopic       =   "Form1"
  11.    Palette         =   "LogIndex.frx":0000
  12.    PaletteMode     =   1  'UseZOrder
  13.    ScaleHeight     =   339
  14.    ScaleMode       =   3  'Pixel
  15.    ScaleWidth      =   461
  16.    Begin VB.PictureBox picBitmap 
  17.       AutoRedraw      =   -1  'True
  18.       Height          =   5055
  19.       Left            =   0
  20.       ScaleHeight     =   4995
  21.       ScaleWidth      =   4320
  22.       TabIndex        =   0
  23.       Top             =   0
  24.       Width           =   4380
  25.    End
  26.    Begin VB.PictureBox picPalette 
  27.       AutoRedraw      =   -1  'True
  28.       Height          =   2460
  29.       Left            =   4440
  30.       ScaleHeight     =   2400
  31.       ScaleWidth      =   2400
  32.       TabIndex        =   1
  33.       Top             =   0
  34.       Width           =   2460
  35.    End
  36.    Begin MSComDlg.CommonDialog dlgOpenFile 
  37.       Left            =   4440
  38.       Top             =   2520
  39.       _ExtentX        =   847
  40.       _ExtentY        =   847
  41.       _Version        =   393216
  42.       CancelError     =   -1  'True
  43.    End
  44.    Begin VB.Menu mnuFile 
  45.       Caption         =   "&File"
  46.       Begin VB.Menu mnuFileOpen 
  47.          Caption         =   "&Open..."
  48.          Shortcut        =   ^O
  49.       End
  50.    End
  51. Attribute VB_Name = "frmLogIndex"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Option Explicit
  57. Private Const PALETTE_INDEX = &H1000000
  58. ' Make the controls as large as possible.
  59. Private Sub Form_Resize()
  60. Dim wid As Single
  61.     picPalette.Left = ScaleWidth - picPalette.Width
  62.     wid = picPalette.Left - 3
  63.     If wid < 10 Then wid = 10
  64.     picBitmap.Move picBitmap.Left, picBitmap.Top, wid, ScaleHeight
  65. End Sub
  66. ' Load an image.
  67. Private Sub mnuFileOpen_Click()
  68. Dim fname As String
  69.     ' Allow the user to pick a file.
  70.     On Error Resume Next
  71.     dlgOpenFile.FileName = "*.BMP;*.WMF;*.DIB;*.JPG;*.GIF"
  72.     dlgOpenFile.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  73.     dlgOpenFile.ShowOpen
  74.     If Err.Number = cdlCancel Then
  75.         Exit Sub
  76.     ElseIf Err.Number <> 0 Then
  77.         Beep
  78.         MsgBox "Error selecting file.", , vbExclamation
  79.         Exit Sub
  80.     End If
  81.     On Error GoTo LoadError
  82.     fname = Trim$(dlgOpenFile.FileName)
  83.     dlgOpenFile.InitDir = Left$(fname, Len(fname) _
  84.         - Len(dlgOpenFile.FileTitle) - 1)
  85.     Caption = "ShowLog [" & fname & "]"
  86.     ' Load the picture.
  87.     picBitmap.Picture = LoadPicture(fname)
  88.     picBitmap.Refresh
  89.     ' Make picPalette use the same logical palette.
  90.     picPalette.Picture = picPalette.Image
  91.     picPalette.Picture.hPal = picBitmap.Picture.hPal
  92.     ' Display the logical palette colors.
  93.     FillPicture
  94.     Exit Sub
  95. LoadError:
  96.     Beep
  97.     MsgBox "Error loading picture " & fname & _
  98.         "." & vbCrLf & Error$, vbExclamation
  99. End Sub
  100. ' Fill picture box Pal with its logical palette
  101. ' colors using palette indexes.
  102. Private Sub FillPicture()
  103. Dim i As Integer
  104. Dim j As Integer
  105. Dim dx As Single
  106. Dim dy As Single
  107. Dim clr As Long
  108.     dx = picPalette.ScaleWidth / 16
  109.     dy = picPalette.ScaleHeight / 16
  110.     clr = 0
  111.     For i = 0 To 16
  112.         For j = 0 To 16
  113.             picPalette.Line (j * dx, i * dy)-Step(dx, dy), _
  114.                 clr + PALETTE_INDEX, BF
  115.             clr = clr + 1
  116.         Next j
  117.     Next i
  118. End Sub
  119. Private Sub Form_Load()
  120.     ' Start the file selection dialog in the
  121.     ' current directory.
  122.     dlgOpenFile.InitDir = App.Path
  123.     ' Fill in the initial palette.
  124.     FillPicture
  125. End Sub
  126.